/*********************************************************************************
Organization 					: 				Georgia Institute of Technology
  
Institute 						:				Cognitive Computing Group(CCL)
 
Authors							: 				Santiago Ontanon, Kinshuk Mishra
 												Neha Sugandh 
 												
Class							:				GoldCondition
 
Function						: 				Provides a class for holding 
												the gold condition class
****************************************************************************/
package planninglanguage.conditions;

import mre.MRE;

import org.jdom.Element;

import util.XMLWriter;
import base.WargusGameState;


public class GoldCondition extends Condition {
	int m_minGold;
	
	public GoldCondition(int a_minGold)
	{
		m_minGold = a_minGold;
	}
	
	public String toString(int tabs) {
	  String n = super.toString(tabs);
	  n = n + "Min Gold is :" + m_minGold;
	  return n;
	}	
	
	public boolean compare(BuildingCompleteCondition c)
	{
		return true;
	}
	
	public boolean test(WargusGameState a_gameState)
	{		
//		System.out.println("GoldCondition: test( gold = " + m_minGold + ")");	
		
		if (a_gameState.getPlayer().getGold()-MRE.allocated_gold >= m_minGold) return true;
		  																  else return false;		
	}
	
	public void writeXML(XMLWriter w) {
		w.tag("condition type=\""+this.getClass().getSimpleName()+"\"");
		{
			w.tag("min-gold", m_minGold);
		}
		w.tag("/condition");
	}
	
	protected static Condition loadConditionFromXML(Element e) {
		return new GoldCondition(Integer.parseInt(e.getChildText("min-gold")));
	}
}
